package mapi;

import io.renren.common.utils.NumberUtil;

import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;

import cn.hutool.crypto.digest.DigestUtil;

public class test001 {
	
	public static void main(String[] args) throws Exception {
		 /*SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
		 parameters.put("body", "test");
		 parameters.put("appid", "wxd930ea5d5a258f4f");
		 parameters.put("nonce_str", "ibuaiVcKdpRxkhJA");
		 parameters.put("device_info", "1000");
		 System.err.println(parameters);
		 String accsiiAscStr=createAccsiiAscStr(parameters);
		 String sgin=createSginStr(accsiiAscStr, "12345678");*/
		
		for(int i=0;i<50;i++){
			double famount=(new Random().nextInt(30)+1)*0.01;
			//System.err.println(famount);
			System.err.println(NumberUtil.sub(100D, famount));
		}
		 
		 
		 
	}
	
   //按照ASCII码排序
   public static String createAccsiiAscStr(SortedMap<Object, Object> parameters) {
        StringBuffer sb = new StringBuffer();
        Iterator<Entry<Object, Object>> it = parameters.entrySet().iterator();//所有参与传参的参数按照accsii排序（升序）
        while (it.hasNext()) {
            Map.Entry<Object, Object> entry = (Entry<Object, Object>) it.next();
            String k = (String) entry.getKey();
            Object v = entry.getValue();
            if (null != v && !"".equals(v)) {//空值不传递，不参与签名组串
                sb.append(k + "=" + v + "&");
            }
        }
        String resultstr = sb.toString().substring(0,sb.toString().length()-1);
        System.err.println("待签名字符串:" + resultstr);//排序后的字符串
        return resultstr ;
   }
   
   //MD5签名
   public static String createSginStr(String accsiiAscStr,String md5str) {
	   String str=accsiiAscStr+"&key="+md5str;
	   System.err.println(str);
	   String reststr=DigestUtil.md5Hex(str).toUpperCase();
	   System.err.println(reststr);
	   return reststr ;
   }
	

}
